package com.cqq.boot.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.cqq.boot.base.BaseController;
import com.cqq.boot.domain.Hotel;
import com.cqq.boot.domain.User;
import com.cqq.boot.service.HotelService;
import com.cqq.boot.service.UserService;
import com.github.pagehelper.Page;

@RestController
@RequestMapping("/handler")
public class TestHandlerController extends  BaseController{

	@Autowired
    private UserService userService;
	@Autowired
	private HotelService hotelService;
	
	@GetMapping("/helloworld")
    public String helloworld() {
        return "helloworld23";
    }
	
	@ResponseBody
	@RequestMapping("/getUserById/{id}")
    public User getUserById(@PathVariable int id) {
        return userService.getUserById(id);
    }
	
	@ResponseBody
	@RequestMapping("/getUsers")
	public List<User> getUsers() {
		return userService.getUsers();
	}
	
	@ResponseBody
	@RequestMapping("/add")
	public int add() {
		User user = new User();
		user.setAge(10);
		user.setCreate(13);
		user.setName("haha");
		return userService.add(user);
	}
	
	@ResponseBody
	@RequestMapping("/addHotel")
	public int addHotel() {
		Hotel hotel = new Hotel();
		hotel.setAddress("徐汇");
		hotel.setCity(2);
		hotel.setName("锦江之星");
		hotel.setZip("200000");
		return hotelService.add(hotel);
	}
	
	@ResponseBody
	@RequestMapping("/getHotels")
	public List<Hotel> getHotels() {
		return hotelService.queryHotels();
	}
	
	@ResponseBody
	@RequestMapping("/queryPageHotel/{pageNo}")
    public Page<Hotel> queryPageHotel(@PathVariable int pageNo) {
        return hotelService.queryPage(pageNo, 1);
    }
	
}
